package com.sky.controller.admin;

import com.sky.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController("adminShopController")
@RequestMapping("admin/shop")
@Slf4j
public class ShopController {

    @Resource
    private StringRedisTemplate stringRedisTemplate;
    private static final String KEY = "SHOP_STATUS";

    /**
     * 设置店铺营业状态
     * @param status
     * @return
     */
    @PutMapping("{status}")
    public Result setStatus(@PathVariable Integer status) {
        log.info("设置店铺营业状态为：{}", status == 1 ? "营业中" : "打样中");
        stringRedisTemplate.opsForValue().set(KEY, status.toString());
        return Result.success();
    }

    /**
     * 获取店铺营业状态
     * @return
     */
    @GetMapping("status")
    public Result<Integer> getStatus() {
        String shopStatus = stringRedisTemplate.opsForValue().get(KEY);
        Integer status = Integer.valueOf(shopStatus);
        log.info("获取店铺营业状态为: {}" , status == 1 ? "营业中" : "打样中");
        return Result.success(status);
    }
}
